import { UserInfo, UserState } from "@/type/store/user";
import { cloneDeep } from "lodash";
const initState: UserState = {
  token: "",
  userId: "",
  userInfo: {
    id: "",
    loginName: "",
    loginPwd: "",
    actualName: "",
    phone: "",
    email: "",
    xAccessToken: "",
    disableFlag: "",
  },
  loginName: "",
};

export default {
  namespaced: true,
  state: cloneDeep(initState),
  mutations: {
    SET_TALLY_BOOK_ACCESS_TOKEN(state: UserState, token: string) {
      state.token = token;
    },
    SET_TALLY_BOOK_USER_ID(state: UserState, userId: number) {
      state.userId = userId;
    },
    SET_USERINFO(state: UserState, userInfo: UserInfo) {
      state.userInfo = userInfo;
    },
    SET_LOGINNAME(state: UserState, loginName: string) {
      state.loginName = loginName;
    },
    CLEAR_USER_STATE(state: UserState) {
      const noClearKeys: any = [];
      for (const key in state) {
        if (!noClearKeys.includes(key)) {
          (state as any)[key] = (initState as any)[key]
        }
      }
    },
  },
  actions: {},
};
